package com.qk.ezbuy.controller;

import com.qk.ezbuy.pojo.User;
import com.qk.ezbuy.service.UserService;
import com.qk.ezbuy.util.Myutil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/Regist")
public class ResourcesController {
    @Autowired
    private UserService userService;

    @RequestMapping("loginNameJudge")
    public Map loginNameJudge(String loginName){
        Map<String,Object> map = new HashMap<String, Object>();
        User user = userService.selectByLoginName(loginName);
        if (user != null) {
            map.put("msg",1);
        }else {
            map.put("msg",2);
        }
        return map;
    }

    @RequestMapping("/Register")
    public Map Regist(User user){
        Map<String,Object> map = new HashMap<String, Object>();
        user.setPassword(Myutil.md5(user.getPassword()));
        int count  = userService.addUser(user);
        if (count>0) {
            map.put("msg",1);
        }else {
            map.put("msg",2);
        }
        return map;
    }

}
